package com.dreamstations.changshads.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/*
    ActicalDetailPagerFrag 中的 ViewPager 的 adapter 。
 */
public class ImagePagerAdapter extends android.support.v4.view.PagerAdapter {

    List<? extends ImageView> list;

    public ImagePagerAdapter(List<? extends ImageView> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        Log.d("instantiateItem", "before");
        container.addView(list.get(position), ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        Log.d("instantiateItem", "after");
        return list.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Log.d("viewpager", "starting removing");
        container.removeView(list.get(position));
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
